

//  const upload = function (blob) {
//     let time = Math.round(100 + 500 * Math.random());
//     return new Promise((resolve, reject) => {
//         // 是否执行测试
//         console.log(`run ${time}ms`);
//         // 成功失败概率50%
//         if (Math.random() > 0.5) {
//             setTimeout(resolve, time, 'promise resolved ' + time + 'ms');
//         } else {
//             setTimeout(reject, time, 'promise rejected ' + time + 'ms');
//         }         
//     });
// };
// (async () => {
//     try {
//         let result = await Promise.race([upload(0), upload(1), upload(2)]);
//         console.log(result);
//     } catch (err) {
//         console.log(err)
//     }
// })()

let getUserInfo = function(user) {
    return new Promise((resolve, reject) => {
        setTimeout(() => resolve('姓名：张三'), Math.floor(400 * Math.random()))
    })
}

let showUserInfo  = function(user) {
    return getUserInfo().then(info => {
        console.log('用户信息', info)
        return true;
    })
}

let timeout = function (delay, result) {
    return new Promise(resolve => {
        setTimeout(() => resolve(result), delay);
    });
}

// loading时间显示需要
const time = +new Date()
let showToast = function () {
    console.log('show loading...')
};
let hideToast = function () {
    console.log('hide loading' + (+new Date() - time));
}
// 执行代码示意
showToast()
Promise.all([showUserInfo(), timeout(200)]).then(() => {
   hideToast();
})

    